#include "SDCF.h"

/* get the module information pf the current bb */
void 
Get_Mod_Info(module_data_t* module)
{
	if (sdcf_status.init){
		if(module->names.module_name){
			if(sdcf_status.in_mod_exe){
				dr_fprintf(f,"%s>>>>>>>>>>>>>>>>>>>>>>\n", module->names.module_name);
			}
			module->names.module_name = module->names.module_name;
			strcpy(sdcf_status.current_module_name,module->names.module_name);
			sdcf_status.in_mod_exe = false;
		}
		else if(module->names.exe_name){
			dr_fprintf(f,"%s>>>>>>>>>>>>>>>>>>>>>>\n", module->names.exe_name);
			module->names.module_name = module->names.exe_name;
			strcpy(sdcf_status.current_module_name,module->names.exe_name);
			sdcf_status.in_mod_exe = true;
		}
	}
	else
	{
		if(module->names.module_name){
			if(strcmp(module->names.module_name, sdcf_status.current_module_name)){
				//dr_fprintf(f,"%s>>>>>>>>>>>>>>>>>>>>>>\n", module->names.module_name);
				strcpy(sdcf_status.current_module_name,module->names.module_name);
				sdcf_status.in_mod_exe = false;
			}
		}
		else if(module->names.exe_name){
			if(strcmp(module->names.exe_name, sdcf_status.current_module_name)){
				dr_fprintf(f,"%s>>>>>>>>>>>>>>>>>>>>>>\n", module->names.exe_name);
				strcpy(sdcf_status.current_module_name,module->names.exe_name);
				sdcf_status.in_mod_exe = true;
			}
		}
	}
}


/* print the instructions in the bb*/
void 
BB_Print(void* drcontext, instrlist_t* bb)
{
	instr_t* cur_instruction;
	instr_t* next_instruction;
	for (cur_instruction = instrlist_first(bb); cur_instruction != NULL; cur_instruction = next_instruction){
		next_instruction = instr_get_next(cur_instruction);
		int cur_opcode = instr_get_opcode(cur_instruction);
		//		if(in_the_outlayer){
		dr_print_instr(drcontext, f, cur_instruction, "");
		//		}
	}
}